//
//  aggregateVC.swift
//  swiftDemo
//
//  Created by yaqiang bi on 2017/3/9.
//  Copyright © 2017年 毕小强. All rights reserved.
//

import UIKit
class aggregateVC: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        
        /// 数组初始化
        let arr1 : Array<String> = ["1","2"]
        let arr2 : [Int] = [1,2,3]
        print(arr1)
        print(arr2)
        
        /// repeating默认值 count个数
        let arr3 = Array(repeating: 0.0, count: 3)
        print(arr3)
        
        /// 可以通过+合并两个兼容类型的数组
        let arr4 = Array(repeating: 2.2, count: 4)
        let sumArr = arr3 + arr4
        print(sumArr)
        
        /// 数组的删减查
        var shopList:[String] = ["面包","香蕉"]
        print("shoplist's count is\(shopList.count)")
        shopList.append("泡泡糖")
        shopList += ["榴莲"]
        print("shoplist's first object is \(shopList.first!)")
        shopList[0] = "饼干"
        print("shoplist \(shopList.isEmpty) is empty")
        shopList += ["糖果","牛奶"]
        print(shopList)
        shopList[1...4] = ["milk","cookie"]
        print(shopList)
        shopList.insert("一点点", at: 4)
        print(shopList)
        print(shopList.remove(at: 3))
        print(shopList)
        print(shopList.removeLast())
        print(shopList)
        
        ///数组的遍历
        for item in shopList {
            print(item)
        }
        for (index,value) in shopList.enumerated() {
            print("\(index):\(value)")
        }
        
        ///初始化合集 Set
        var favoriteGenres:Set<String> = ["风","雨","雷","电"]
        for str in favoriteGenres {
            print(str)
        }
        favoriteGenres.insert("风")
        for str in favoriteGenres {
            print(str)
        }
        favoriteGenres.remove("雨")
        for str in favoriteGenres {
            print(str)
        }
        if favoriteGenres.contains("风") {
            print("有风")
        }else{
            print("无风")
        }
        let favoriteArr = favoriteGenres.sorted()
        print(favoriteArr)
        
        let newSet:Set<String> = ["风","天空","大地"]
        //交集
        print("交集:\(favoriteGenres.intersection(newSet))")
        //并集
        print("并集:\(favoriteGenres.union(newSet))")
        //补集
        print("补集:\(favoriteGenres.subtracting(newSet))")
        //合集
        print("合集:\(favoriteGenres.symmetricDifference(newSet))")
        
        /// 字典
        var mutablDic = Dictionary<Int,String>()
        mutablDic[1] = "one"
        print("字典有\(mutablDic.count)个成员")
        if mutablDic.isEmpty {
            print("这个字典里有内容")
        }
        mutablDic[2] = "two"
        print(mutablDic.updateValue("二", forKey: 2) ?? "更新成功")
        mutablDic[1] = nil
        if let one = mutablDic[1] {
            print(one)
        }else{
            print("键值1处没有值")
        }
        mutablDic.updateValue("one", forKey: 1)
        mutablDic.updateValue("three", forKey: 3)
        if let three = mutablDic.removeValue(forKey: 3) {
            print(three)
        }else{
            print("删你妹啊,这没东西")
        }
        for (key,value) in mutablDic {
            print("key:\(key) value:\(value)")
        }
        for key in mutablDic.keys{
            print("key:\(key)")
        }
        for value in mutablDic.values {
            print("value:\(value)")
        }
        let valueArr = [String](mutablDic.values)
        print(valueArr)
        let keyArr = [Int](mutablDic.keys)
        print(keyArr)
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
